package api

import (
	"MxShop/global"
	"MxShop/proto"
	"MxShop/service"
	"context"
	"github.com/gin-gonic/gin"
)

func UserLogin(ctx *gin.Context) {
	//调用rpc端
	name := ctx.DefaultQuery("name", "孙波")
	password := ctx.DefaultQuery("password", "111111")
	data, err := global.UserClient.UserLogin(context.Background(), &proto.LoginRequest{
		Name:     name,
		Password: password,
	})
	if err != nil {
		ctx.JSON(400, gin.H{
			"msg": "Api调用rpc连接失败",
		})
	}
	token := service.CreateToken(int32(data.Id), data.Name)
	ctx.JSON(200, gin.H{
		"msg":  "调用成功",
		"data": token,
	})
}

func GetBarginList(ctx *gin.Context) {
	result, err := global.UserClient.GetBarginList(context.Background(), &proto.PageInfo{
		Pn:    0,
		PSize: 10,
	})
	if err != nil {
		ctx.JSON(400, gin.H{
			"msg": "Api调用rpc连接失败",
		})
	}
	ctx.JSON(200, gin.H{
		"msg":  "调用成功",
		"data": result,
	})
}
